package com.zerui.manager.web;

import com.zerui.authority.annotation.Authorize;
import com.zerui.cola.dto.Response;
import com.zerui.manager.access.auth.task.domain.AuthTask;
import com.zerui.manager.access.auth.task.gateway.AuthTaskGateway;
import com.zerui.manager.app.access.AuthTaskManager;
import com.zerui.manager.web.vo.AccessAuthTaskVO;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Validated
@Api(value = "门禁授权管理", tags = "门禁设备管理")
@RestController
@RequestMapping("/api/v1/access/auth/task")
@Authorize(value = {"access-control-manager:admin-auth"})
public class AccessAuthTaskController {

    @Resource
    private AuthTaskGateway authTaskGateway;
    @Resource
    private AuthTaskManager authTaskManager;

    /**
     * 这里用于测试使用
     *
     * @param authTaskVO 入参
     * @return
     * @author zhangpingyan
     */
    @PostMapping("/start")
    public Response startAuthTask(@RequestBody AccessAuthTaskVO authTaskVO) {
        AuthTask authTask = authTaskGateway.selectByTaskId(authTaskVO.getId());
        if (null != authTask) {
            authTaskManager.startAuthTask(authTaskVO.getId());
        }
        return Response.buildSuccess();
    }

}
